package cn.edu.lingnan.controller;


import cn.edu.lingnan.common.JsonResult;
import cn.edu.lingnan.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 文韬
 * @since 2022-06-24
 */
@Controller
@RequestMapping("/user")
public class UserController {

    //注入业务层对象
    @Autowired
    private UserService userService;

    //用户登录
    @PostMapping("/dologin")
    @ResponseBody
    public JsonResult<Void> dologin(String uAccount, String uPassWord, String uPower, HttpSession session){
        return userService.dologin(uAccount,uPassWord,uPower,session);
    }

    //检查用户手机号码是否正确
    @GetMapping("/checkUserPhone")
    @ResponseBody
    public JsonResult<Void> checkLoginuAccount(String userPhone) {
        return userService.checkLoginuAccount(userPhone);
    }

    //注册
    @PostMapping("/doReg")
    @ResponseBody
    public JsonResult<Void> doReg(String uName,String uAccount, String uPassWord,String confirmPwd, String uPower,String uEmail, HttpSession session){
        return userService.doReg(uName,uAccount,uPassWord,confirmPwd,uPower,uEmail,session);
    }

    //检查注册账号------------------
    @PostMapping("/checkuAccount")
    @ResponseBody
    public JsonResult<Void> checkReguAccount(String uAccount) {
        return userService.checkReguAccount(uAccount);
    }

    //检查密码一致性------------------
    @PostMapping("/checkPwd")
    @ResponseBody
    public JsonResult<Void> checkPwd(String uPassWord, String confirmPwd) {
        return userService.checkuPasswordAndConfirmPwd(uPassWord, confirmPwd);
    }

    //验证邮箱--------------------
    @PostMapping("/checkEmail")
    @ResponseBody
    public JsonResult<Void> checkEmail(String uEmail) {
        return userService.checkEmail(uEmail);
    }

    //==============================================================
    //用户部分-----------------------------
    //跳转到主页
    @GetMapping("/toindex")
    public String toIndex(){
        return "student/index.html";
    }

    //跳转到登录页面
    @GetMapping("/toUserLogin")
    public String toUserLoginPage(){
        return "login.html";
    }
}

